package com.kwok.ssm.springmvc.controller;

import com.kwok.ssm.springmvc.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

//@Controller
//@ResponseBody
@RestController
@RequestMapping("/restful")
public class RestfulController {

//    @Autowired
//    private XxxService xxxService;

    //@RequestMapping(value = "/create", method = RequestMethod.POST)
    @PostMapping("/create")
    public String create(@RequestBody User user) {
        //Integer save = xxxService.save(user);
        System.out.println(user);
        return "create";
    }


    //@RequestMapping(value = "/read", method = RequestMethod.GET)
    @GetMapping("/read")
    public List<User> read() {
        User user1 = new User(1, "用户一", new Date("1997-01-01"));
        User user2 = new User(2, "用户二", new Date("1997-12-31"));
        List<User> users = new ArrayList<User>();
        users.add(user1);
        users.add(user2);
        return users;
    }

    @PutMapping("/update")
    public String update(@RequestBody User user) {
        //Integer modify = xxxService.modify(user);
        System.out.println(user);
        return "update";
    }

    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable("id") Integer id) {
        //Integer remove = xxxService.removeById(id);
        return "delete";
    }

}
